/*
 * @Author: Wxx
 * @Date: 2022-02-22 11:37:24
 * @LastEditors: Wxx
 * @LastEditTime: 2022-02-22 14:06:19
 * @Description:
 */
import { useState, useEffect } from "react";
import axios from "axios";
function ToDoList() {
  const [list, setList] = useState([]);
  // 通过给useEffect的第二个参数传一个空数组 实现类似class组件中的componentDidMount生命周期
  // 在组件加载时执行
  useEffect(() => {
    axios("test.json").then((res) => {
      setList(res.data.data.films);
    });
  }, []);
  return (
    <div>
      <h2>电影推荐</h2>
      <ul>
        {list.map((item, index) => (
          <li key={item.filmId} style={{ marginTop: 16 }}>
            {item.name}
          </li>
        ))}
      </ul>
    </div>
  );
}
export default ToDoList;
